home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 039a / netpq203.zip / MENUDRVR.C < prev    next >
Text File  |  1993-03-01  |  3KB  |  133 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. #include "nos.h"
  5. #include "noslib.h"
  6. #include "netpq.h"
  7. #include "proto.h"
  8.  
  9. int selection, xbase, ybase;
  10.  
  11.  
  12. int menu (char *prompts [], int numberofprompts, int xsize, int x, int y)
  13.     {
  14.     //    displays the prompts in *prompts as a menu and allows the operator
  15.     //    to select one of the prompts through use of the cursor keys.
  16.  
  17.     int i;
  18.  
  19.     xbase = x;
  20.     ybase = y;
  21.     selection = 0;
  22.  
  23.     gotoxy (xbase, (ybase++) );
  24.     nohighlight ();
  25.     cprintf (" ╔");
  26.     for (i = 1; i <= xsize; i++)
  27.     cprintf ("═");
  28.     cprintf ("╗ ");
  29.  
  30.     while (selection < numberofprompts)
  31.     {
  32.     displayoneprompt (prompts, xsize, false);
  33.     selection++;
  34.     }
  35.  
  36.     gotoxy (xbase, (ybase + selection) );
  37.     cprintf (" ╚");
  38.     for (i = 1; i <= xsize; i++)
  39.     cprintf ("═");
  40.     cprintf ("╝ ");
  41.  
  42.     getchoice (prompts, xsize, numberofprompts);
  43.  
  44.     return selection;
  45.     }
  46.  
  47.  
  48.  
  49. int getchoice (char *prompts [], int xsize, int numberofprompts)
  50.     {
  51.     //    handles operator actions
  52.  
  53.     selection = 0;
  54.  
  55.     while (true)
  56.     {
  57.     displayoneprompt (prompts, xsize, true);
  58.  
  59.     while (kbhit () == 0);
  60.  
  61.     switch (getextch ())
  62.         {
  63.         case key_home:
  64.         displayoneprompt (prompts, xsize, false);
  65.         selection = 0;
  66.         break;
  67.  
  68.         case key_end:
  69.         displayoneprompt (prompts, xsize, false);
  70.         selection = numberofprompts - 1;
  71.         break;
  72.  
  73.         case key_cursorup:
  74.         displayoneprompt (prompts, xsize, false);
  75.         do
  76.             {
  77.             selection--;
  78.             if (selection < 0)
  79.             selection = numberofprompts - 1;
  80.             }
  81.             while (strlen (prompts [selection]) == 0);
  82.         break;
  83.  
  84.         case key_cursordown:
  85.         displayoneprompt (prompts, xsize, false);
  86.         do
  87.             {
  88.             selection++;
  89.             if (selection >= numberofprompts)
  90.             selection = 0;
  91.             }
  92.             while (strlen (prompts [selection]) == 0);
  93.         break;
  94.  
  95.         case key_esc:
  96.         case key_cursorleft:
  97.         displayoneprompt (prompts, xsize, false);
  98.         selection = -1;
  99.  
  100.         case key_enter:
  101.         case key_cursorright:
  102.         return (selection);
  103.  
  104.         default:
  105.         printf ("\a");
  106.         }
  107.     }
  108.     }
  109.  
  110.  
  111.  
  112.  
  113. void displayoneprompt (char *prompts [], int xsize, int flag)
  114.     {
  115.     //    displays one prompt string
  116.  
  117.     gotoxy (xbase, (ybase + selection) );
  118.  
  119.     cprintf (" ║");
  120.  
  121.     if (flag == true)
  122.     highlight ();
  123.     else
  124.     nohighlight ();
  125.  
  126.     cprintf ("%-*s", xsize, prompts [selection]);
  127.  
  128.     nohighlight ();
  129.     cprintf ("║ ");
  130.  
  131.     gotoxy ( (xbase + 2), (ybase + selection) );
  132.     }
  133.